package january.test_1_24;

import java.util.Scanner;

public class TestMain3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double m = scanner.nextInt();
        double n = scanner.nextInt();
        char[] arr = A(m,n);
        for(int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]);
        }
    }
    public static char[] A(double m,double n) {
         int c = C(m,n);
         char[] arr = new char[c];
         for(int i = 0; i < c; i++) {
             double tmp = Math.pow(n,c - i - 1);
             if(m >= tmp) {
                 double b = m/tmp;
                 if(b > 9) {
                     b = b - 9;
                     char a = (char) ('A' + b);
                     arr[c-1-i] = a;
                     m = m - (int)b*(int)Math.pow(n,(c-i - 1));
                 } else {
                     char a = (char) ('0' + b);
                     arr[c-1-i] = a;
                     m = m - (int)b*(int)Math.pow(n,(c-i - 1));
                 }
             } else {
                 arr[c-1-i] = '0';
             }
         }
         return arr;
    }
    public static int C(double m,double n) {
        int i = 1;
        while (true) {
            if(Math.pow(n,i) >= m) {
                return i ;
            }
            i++;
        }
    }
}
